from ._base import db
from .satree import TreeMixin


class Folder(db.Model,TreeMixin):
    __tablename__ = "folder"
    __tree_output_fields__ = ["id", "name", "item_content"]
    # tree_id = db.Column(db.Integer, default=0)  # 用来标识节点是哪一棵树的,默认为零,如果指定__tree_key__为其他值时，则以__tree_key__字段什来标识树，该字段就没有用。
    tree_id = db.Column(db.Integer, default=1)
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=True)
    # content = db.Column(db.String(20), nullable=True)
    parent_id = db.Column(db.String(20))
    # tree_left = db.Column(db.Integer, default=0)
    # tree_right = db.Column(db.Integer, default=0)
    # tree_level = db.Column(db.Integer, default=0)
    status = db.Column(db.Integer, nullable=True, default=1) #1「活跃」2「暂停」3「已完成」4「已丢弃」
    is_valid = db.Column(db.Integer, nullable=True, default=1)
    create_time = db.Column(db.DateTime,nullable=False)
    create_person = db.Column(db.Integer,nullable=False)
    edit_time = db.Column(db.DateTime, nullable=False)
    edit_person = db.Column(db.Integer,nullable=False)


class Item(db.Model,TreeMixin):
    """
    # 如果l-r = 1 就是action 否者是project；
    """
    __tablename__ = "item"
    __tree_output_fields__ = ["id","name","item_content"]
    # tree_id = db.Column(db.Integer, default=0)  # 用来标识节点是哪一棵树的,默认为零,如果指定__tree_key__为其他值时，则以__tree_key__字段什来标识树，该字段就没有用。
    tree_id = db.Column(db.Integer, default=2)
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=True)
    content = db.Column(db.String(20), nullable=True) # 注释
    parent_id = db.Column(db.String(20),db.ForeignKey(id))
    folder_id = db.Column(db.Integer, db.ForeignKey(Folder.id))
    status = db.Column(db.Integer, nullable=True, default=1)  # 1「活跃」2「暂停」3「已完成」4「已丢弃」
    Flag = db.Column(db.Integer, nullable=True, default=0)  # 0「no flag」1「flagged」
    Type = db.Column(db.Integer)  # 1:顺序、2：平行、3：单个动作
    repeat_type = db.Column(db.Integer)  # 0:不重复、11：每天、12：每周、13:每月、14:每年、10：公历自定义、20:农历自定义
    repeat_time = db.Column(db.Integer)
    is_valid = db.Column(db.Integer, nullable=True, default=1)
    start_time = db.Column(db.DateTime, nullable=False)
    due_time = db.Column(db.DateTime, nullable=False)
    end_time = db.Column(db.DateTime, nullable=False)
    create_time = db.Column(db.DateTime, nullable=False)
    create_person = db.Column(db.Integer, nullable=False)
    edit_time = db.Column(db.DateTime, nullable=False)
    edit_person = db.Column(db.Integer, nullable=False)
    # tree_left = db.Column(db.Integer, default=0)
    # tree_right = db.Column(db.Integer, default=0)
    # tree_level = db.Column(db.Integer, default=0)



class Context(db.Model,TreeMixin):
    __tablename__ = "context"
    __tree_output_fields__ = ["id","name","item_content"]
    # tree_id = db.Column(db.Integer, default=0)  # 用来标识节点是哪一棵树的,默认为零,如果指定__tree_key__为其他值时，则以__tree_key__字段什来标识树，该字段就没有用。
    tree_id = db.Column(db.Integer, default=3)
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=True)
    content = db.Column(db.String(20), nullable=True)
    parent_id = db.Column(db.String(20))
    project_id = db.Column(db.Integer, db.ForeignKey(Folder.id))
    # tree_left = db.Column(db.Integer, default=0)
    # tree_right = db.Column(db.Integer, default=0)
    # tree_level = db.Column(db.Integer, default=0)
    # status = db.Column(db.Integer, nullable=True, default=1) #1「活跃」2「暂停」3「已完成」4「已丢弃」
    is_valid = db.Column(db.Integer, nullable=True, default=1)
    create_time = db.Column(db.DateTime,nullable=False)
    create_person = db.Column(db.Integer,nullable=False)
    edit_time = db.Column(db.DateTime, nullable=False)
    edit_person = db.Column(db.Integer,nullable=False)